require('../css/start.less');

// 开始训练页
document.ready(function () {

    // 视频封面 返回按钮跳转
    let returnB = document.querySelector('#return');
    returnB.addEventListener('click', function () {
        // location.href = "./practice.html";
        history.back();
    })

    const URL = 'http://139.9.177.51:8099';
    let imgs = document.querySelector('.fengMian img');
    let text1 = document.querySelector('.text1');  //视频介绍
    let title = document.querySelector('.title');  //视频标题
    // 开始训练按钮跳转
    let btn = document.querySelector('.btn');
    let videoList = null;


    //  获取上个页面参数 转换为对象
    let obj = utils.formateSearch(location.search);
    // console.log(obj);

    // 接口请求
    http.get('/sports/courseDetail?id=' + obj.id, function (res) {
        console.log(res);
        // 获取封面图片，视频标题，视频介绍的数据 渲染页面
        imgs.src = URL + res.data.imgurl;
        title.innerText = res.data.name;
        text1.innerText = res.data.desc;
        // 把所有的视频存到全局
        videoList = res.data.fragments;
        console.log(videoList);
    })





    // 开始训练按钮点击跳转事件
    btn.addEventListener('click', function () {
        sessionStorage.setItem('videoList', JSON.stringify(videoList));
        location.href = './info.html';
    })

    // 点击视频预览封面也能跳转进去
    let starBtn = document.querySelector('.star');
    starBtn.addEventListener('click', function () {
        sessionStorage.setItem('videoList', JSON.stringify(videoList));
        location.href = './info.html';
    })












})